package wiinf;

import javax.swing.*;

/**
 *
 * @author Randy van Heijst
 */
public class oplVerwijderen extends javax.swing.JPanel {
    private serverViewModel model;

    /**
     * Aanmaken nieuwe panel voor opleidingen verwijderen
     *
     * @param model De JFrame waar de panel in komt
     */
    public oplVerwijderen(serverViewModel model) {
        this.model = model;
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        CoplAfdeling = new javax.swing.JComboBox();
        CoplOpleiding = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        BoplVerwijderen = new javax.swing.JButton();

        CoplAfdeling.setModel(new javax.swing.DefaultComboBoxModel(new String[] {}));
        model.setAfdelingBox(CoplAfdeling);
        CoplAfdeling.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CoplAfdelingActionPerformed(evt);
            }
        });

        CoplOpleiding.setModel(new javax.swing.DefaultComboBoxModel(new String[] {}));

        jLabel1.setText("Afdeling:");

        jLabel2.setText("Opleiding:");

        BoplVerwijderen.setText("Verwijder");
        BoplVerwijderen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BoplVerwijderenActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(164, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(jLabel2))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(CoplOpleiding, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(CoplAfdeling, javax.swing.GroupLayout.Alignment.TRAILING, 0, 168, Short.MAX_VALUE)))
                    .addComponent(BoplVerwijderen, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CoplAfdeling, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CoplOpleiding, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 141, Short.MAX_VALUE)
                .addComponent(BoplVerwijderen)
                .addGap(53, 53, 53))
        );
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Action listener voor combo box gevuld met opleidingen
     *
     * @param evt Action event
     */
    private void CoplAfdelingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CoplAfdelingActionPerformed
        JComboBox cb = (JComboBox)evt.getSource();
        String afdeling = (String)cb.getSelectedItem();
        
        String[] opleiding = model.server.fh.getOpleiding(afdeling);
        CoplOpleiding.removeAllItems();
        if (opleiding.length > 0){
            for (int i = 0; i<opleiding.length; i++){
                CoplOpleiding.addItem(opleiding[i].replace(".xml",""));
            }
        }
    }//GEN-LAST:event_CoplAfdelingActionPerformed

    /**
     * Actionlistener horende bij de verwijder button
     *
     * @param evt Action event
     */
    private void BoplVerwijderenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BoplVerwijderenActionPerformed
        String afdeling = CoplAfdeling.getSelectedItem().toString();
        String opleiding = CoplOpleiding.getSelectedItem().toString();
        model.server.deleteOpleiding(afdeling,opleiding);
    }//GEN-LAST:event_BoplVerwijderenActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BoplVerwijderen;
    private javax.swing.JComboBox CoplAfdeling;
    private javax.swing.JComboBox CoplOpleiding;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables

}
